package org.atovio.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.atovio.mybatis.pojo.CV;
import org.atovio.mybatis.pojo.People;

/**
 * 一对一查询
 * 这个设计是乱的。我的理解是，应该一个表对应一个类，这个类里编写了两个表的查询
 *
 * @author AtoVio, Winter Yuan
 */
public interface PeopleOneToOneMapper {

    @Select("""
            select id, name, sex, age
            from cv
            where id = #{cvId}
            """)
    CV selectByCvId(Integer cvId);

    @Select("select * from people where id = #{id}")
    @Results(@Result(
            column = "cv_id", property = "cv",
            one = @One(
                    select = "org.atovio.mybatis.mapper.PeopleOneToOneMapper.selectByCvId",
                    fetchType = FetchType.LAZY))
    )
    People selectWithCvById(Integer id);
}
